package school30.io.fs;

import java.io.IOException;
import java.io.InputStream;
import javax.microedition.io.file.FileConnection;
import school30.io.FileConnector;
import school30.io.FileReader;

public class FsReader extends FileReader{
    FileConnection fc;
    InputStream is;

    public FsReader(FileConnection fc)
    {
        try {
            this.fc = fc;
            this.is = fc.openInputStream();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }

    public long read(byte[] b, long numbytes) {
        try {
            return is.read(b, 0, (int) numbytes);
        } catch (IOException ex) {
            ex.printStackTrace();
            return -1;
        }
    }

    public long size() {
        try {
            return fc.fileSize();
        } catch (IOException ex) {
            return -1;
        }
    }

    public void close() {
        try {
            fc.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
